import i18n from "/src/components/node-kantboot/libs/i18n/index.js";

let result = {};

/**
 * 获取设备协议列表
 */
result.getProtocolList = () => {
    return [
        {
            label: "ModBus RTU",
            value: "modbusRTU"
        },
        {
            label: "ModBus TCP",
            value: "modbusTCP"
        },
        {
            label: "MLINK TCP",
            value: "mlinkTCP"
        },
        {
            label: "Hj212-2017",
            value: "hj212_2017"
        },
        {
            label: "MLINK MQTT",
            value: "mlinkMQTT"
        },
        {
            label: "ZLAN MQTT",
            value: "zlanMQTT"
        }
    ];
}

/**
 * 根据协议编码获取协议名称
 */
result.getProtocolLabel = (protocolCode) => {
    let protocolList = result.getProtocolList();
    for (let i = 0; i < protocolList.length; i++) {
        if (protocolList[i].value === protocolCode) {
            return protocolList[i].label;
        }
    }
    return "";
}

/**
 * 获取数据类型列表
 */
result.getDataTypeList = () => {
    return [
        {
            // label: "数据属性",
            label: i18n.zhToGlobal("数据属性"),
            value: "dataType"
        },
        {
            // label: "配置属性",
            label: i18n.zhToGlobal("配置属性"),
            value: "configType"
        }
    ];
}

/**
 * 根据数据类型编码获取数据类型名称
 */
result.getDataTypeLabel = (dataTypeCode) => {
    let dataTypeList = result.getDataTypeList();
    for (let i = 0; i < dataTypeList.length; i++) {
        if (dataTypeList[i].value === dataTypeCode) {
            return dataTypeList[i].label;
        }
    }
    return "";
}



/**
 * 获取传感器类型列表
 */
result.getSensorTypeList = () => {
    return [
        {
            // label: "数字类型",
            label: i18n.zhToGlobal("数字类型"),
            value: "number"
        },
        {
            // label: "状态类型",
            label: i18n.zhToGlobal("状态类型"),
            value: "status"
        },
        {
            // label: "开关类型",
            label: i18n.zhToGlobal("开关类型"),
            value: "boolean"
        },
        {
            // label: "GPS类型",
            label: i18n.zhToGlobal("GPS类型"),
            value: "gps"
        }
    ];
}

/**
 * 根据传感器类型编码获取传感器类型名称
 */
result.getSensorTypeLabel = (sensorTypeCode) => {
    let sensorTypeList = result.getSensorTypeList();
    for (let i = 0; i < sensorTypeList.length; i++) {
        if (sensorTypeList[i].value === sensorTypeCode) {
            return sensorTypeList[i].label;
        }
    }
    return "";
}


/**
 * 获取对应的单位列表
 */
result.getUnitList = () => {
    return [
        {
            label: "°C",
            value: "degreesCelsius"
        },
        {
            label: "RH",
            value: "relativeHumidity"
        },
        {
            label: "Lux",
            value: "illuminance"
        },
        {
            // label: "有人/无人",
            label: i18n.zhToGlobal("有人/无人"),
            value: "occupancy"
        },
        {
            // label: "打开/关闭",
            label: i18n.zhToGlobal("打开/关闭"),
            value: "openClose"
        },
        {
            label: "ppm",
            value: "partsPerMillion"
        },
        {
            label: "mg/m3",
            value: "milligramsPerCubicMeter"
        },
        {
            label: "%",
            value: "percent"
        },
        {
            label: "m/s",
            value: "metersPerSecond"
        },
        {
            label: "pa",
            value: "pascal"
        },
        {
            label: "°",
            value: "degrees"
        },
        {
            // label: "风向",
            label: i18n.zhToGlobal("风向"),
            value: "windDirection"
        },
        {
            label: "mm",
            value: "millimeter"
        },
        {
            label: "Kn",
            value: "knot"
        }
    ];
}

/**
 * 根据单位编码获取单位名称
 */
result.getUnitLabel = (unitCode) => {
    let unitList = result.getUnitList();
    for (let i = 0; i < unitList.length; i++) {
        if (unitList[i].value === unitCode) {
            return unitList[i].label;
        }
    }
    return "";
}

/**
 * 存储策略数值转换
 * num
 *      * 存储策略
 *      * -2：变化存储
 *      * -1：实时存储
 *      * 其它：存储周期（单位：秒）
 *      *
 */
result.getStorageStrategy = (num) => {
    if(num === -2) {
        return i18n.zhToGlobal("变化存储");
    }
    if(num === -1) {
        return i18n.zhToGlobal("实时存储");
    }
    // 根据存储周期的单位转换，秒、分钟、小时、天
    if(num < 60) {
        return num +" "+ i18n.zhToGlobal("秒");
    }
    if(num < 3600) {
        return num / 60 +" "+ i18n.zhToGlobal("分钟");
    }
    if(num < 86400) {
        return num / 3600 +" "+ i18n.zhToGlobal("小时");
    }
    return num / 86400 +" "+ i18n.zhToGlobal("日");
}

// SensorParamTypeCode
// 传感器属性种类
//      * 属性种类编码
//      * modbus:modbus
//      * 默认:default
result.getSensorParamTypeCodeList = () => {
    return [
        {
            label: "Modbus",
            value: "modbus"
        },
        {
            label: i18n.zhToGlobal("默认"),
            value: "default"
        }
    ];
}

result.getSensorParamTypeCodeLabel = (sensorParamTypeCode) => {
    let sensorParamTypeCodeList = result.getSensorParamTypeCodeList();
    for (let i = 0; i < sensorParamTypeCodeList.length; i++) {
        if (sensorParamTypeCodeList[i].value === sensorParamTypeCode) {
            return sensorParamTypeCodeList[i].label;
        }
    }
    return "";
}

/**
 * rwTypeCode
 * 只读：r
 * 读写：rw
 */
result.getRwTypeCodeList = () => {
    return [
        {
            label: i18n.zhToGlobal("只读"),
            value: "r"
        },
        {
            label: i18n.zhToGlobal("读写"),
            value: "rw"
        }
    ];
}

result.getRwTypeCodeLabel = (rwTypeCode) => {
    let rwTypeCodeList = result.getRwTypeCodeList();
    for (let i = 0; i < rwTypeCodeList.length; i++) {
        if (rwTypeCodeList[i].value === rwTypeCode) {
            return rwTypeCodeList[i].label;
        }
    }
    return "";
}



/**
 * 数据格式编码
 * 16位 无符号数：16:u
 * 16位 有符号数：16:d
 * 32位 无符号数：32:u
 * 32位 有符号数：32:d
 * 32位 浮点型数：32:f
 */
// @Column(name = "t_data_format_code")
// private String dataFormatCode;
result.getDataFormatCodeList = () => {
    return [
        {
            label: i18n.zhToGlobal("16位 无符号数"),
            value: "16:u"
        },
        {
            label: i18n.zhToGlobal("16位 有符号数"),
            value: "16:d"
        },
        {
            label: i18n.zhToGlobal("32位 无符号数"),
            value: "32:u"
        },
        {
            label: i18n.zhToGlobal("32位 有符号数"),
            value: "32:d"
        },
        {
            label: i18n.zhToGlobal("32位 浮点型数"),
            value: "32:f"
        }
    ]
}

result.getDataFormatCodeLabel = (dataFormatCode) => {
    let dataFormatCodeList = result.getDataFormatCodeList();
    for (let i = 0; i < dataFormatCodeList.length; i++) {
        if (dataFormatCodeList[i].value === dataFormatCode) {
            return dataFormatCodeList[i].label;
        }
    }
    return "";
}

/**
 * 数据顺序编码
 * 只针对32位数据有效
 * AB CD
 * AB:高位
 * CD:低位
 * 选项
 * AB_CD: AB CD
 * CD_AB: CD AB
 * DC_BA: DC BA
 * BA_DC: BA DC
 */
// @Column(name = "t_data_order_code")
// private String dataOrderCode;
result.getDataOrderCodeList = () => {
    return [
        {
            label: "AB CD",
            value: "AB_CD"
        },
        {
            label: "CD AB",
            value: "CD_AB"
        },
        {
            label: "DC BA",
            value: "DC_BA"
        },
        {
            label: "BA DC",
            value: "BA_DC"
        }
    ]
}

result.getDataOrderCodeLabel = (dataOrderCode) => {
    let dataOrderCodeList = result.getDataOrderCodeList();
    for (let i = 0; i < dataOrderCodeList.length; i++) {
        if (dataOrderCodeList[i].value === dataOrderCode) {
            return dataOrderCodeList[i].label;
        }
    }
    return "";
}


export default result;